import store from '@/store'
import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
//首页
import Home from '../views/Home/Home.vue'
//登录注册
import Login from '../views/user/Login.vue'
import Register from '../views/user/Register.vue'

//用户管理
import User from '../views/user/User.vue'

// 收支管理
import Income from '../views/payment/Income.vue'
import Pay from '../views/payment/Pay.vue'

// 账户总览
import Property from '../views/property/Property.vue'

// 零花钱管理
import Petals from '../views/petals/Petals.vue'

// 负债管理
import Liabilities from '../views/liabilities/Liabilities.vue'

const routes = [
  {
    path: '/',
    component: () => import('../views/Manage.vue'),
    redirect: '/home',
    children: [
      //首页
      { path: 'home', name: '首页', component: Home },
      //用户管理
      { path: 'user', name: '管理员', component: User },
      //收支管理
      { path: 'income', name: '收入详情', component: Income },
      { path: 'pay', name: '支出详情', component: Pay },
      // 账户总览
      { path: 'property', name: '活期资产', component: Property },
      // 负债详情
      { path: 'liabilities', name: '负债详情', component: Liabilities },
      // 零花钱管理
      { path: 'petals', name: '零花钱', component: Petals }
    ]
  },
  //登录注册
  { path: '/login', name: 'login', component: Login },
  { path: '/register', name: 'Register', component: Register }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  //设置当前路由名称,为了在Header组件中去使用
  localStorage.setItem('currentPathName', to.name)
  store.commit("setPath")//触发store的数据更新
  next()
})

export default router
